/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-09-06
 * Time: 21:50
 */
class Solution5 {
    public String addStrings(String num1, String num2) {
        StringBuilder ret = new StringBuilder();

        int cur1 = num1.length()-1, cur2 = num2.length()-1;
        int t = 0;

        while(cur1 >= 0 || cur2 >= 0 || t != 0) {
            if(cur1 >= 0) {
                t += num1.charAt(cur1)-'0';
                cur1--;
            }
            if(cur2 >= 0) {
                t += num2.charAt(cur2)-'0';
                cur2--;
            }

            ret.append((char)('0'+(char)t % 10));
            t /= 10;
        }

        ret.reverse();

        return ret.toString();
    }

}
